Column

Barplot

Column

Scatterplot

Boxplot

---
title: "Dashboard for Restaurant Inspections"
output: 
  flexdashboard::flex_dashboard:
    orientation: columns
    vertical_layout: fill
    source: embed
---

```{r setup, include=FALSE}
library(flexdashboard)
library(p8105.datasets)
library(tidyverse)
library(plotly)
library(htmlwidgets)
data("rest_inspec")

nrow(rest_inspec)
ncol(rest_inspec)
str(rest_inspec)

rest_inspec = rest_inspec %>% 
  janitor::clean_names() %>%
  drop_na()
```

Column {data-width=650}
-----------------------------------------------------------------------

### Barplot

```{r}
rest_borough = rest_inspec %>% 
  count(boro) %>% 
  mutate(boro = fct_reorder(boro, n)) |> 
  plot_ly(x = ~boro, y = ~n, color = ~boro, type = "bar", colors = "viridis")
rest_borough
```

Column {data-width=350}
-----------------------------------------------------------------------

### Scatterplot

```{r}
rest_scat = rest_inspec %>%
  group_by(camis) %>%
  summarise(mean_score = mean(score, na.rm = TRUE), n_violations = n()) %>%
  plot_ly(x = ~n_violations, y = ~mean_score, type = "scatter", mode = "markers", marker = list(opacity = 0.5))
rest_scat
```

### Boxplot

```{r}
rest_cuisine = rest_inspec %>% 
  group_by(cuisine_description) %>%
  filter(n() > 500) %>%  
  ungroup() %>%
  mutate(cuisine_description = fct_reorder(cuisine_description, score, median)) %>% 
  plot_ly(x = ~score, y = ~cuisine_description, type = "box", colors = "pink")
rest_cuisine
```